/*
*  Copyright 2019-2025 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package me.zhengjie.modules.finance.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.finance.domain.FinanceAd01;
import me.zhengjie.modules.finance.domain.FinanceAd02;
import me.zhengjie.modules.finance.domain.dto.FinanceAd01QueryCriteria;
import me.zhengjie.modules.finance.domain.dto.FinanceAd02QueryCriteria;
import me.zhengjie.modules.finance.service.FinanceAd02Service;
import me.zhengjie.tool.MyMap;
import me.zhengjie.utils.PageResult;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * @Author ly
 * @Description
 * @Date 15:42 2025/6/8
 **/
@RestController
@RequiredArgsConstructor
@Api(tags = "api")
@RequestMapping("/api/financeAd02")
public class FinanceAd02Controller {

	private final FinanceAd02Service financeAd02Service;

	@ApiOperation("导出数据")
	@GetMapping(value = "/download")
	@PreAuthorize("@el.check('financeAd02:list')")
	public void exportFinanceAd01(HttpServletResponse response, FinanceAd02QueryCriteria criteria) throws IOException {
		financeAd02Service.download(financeAd02Service.queryAll(criteria), response);
	}

	@GetMapping("/getBills")
	@ApiOperation("查询单据信息")
	public ResponseEntity<PageResult<FinanceAd01>> getBills(FinanceAd01QueryCriteria criteria,FinanceAd01 financeAd01) {
		Page<Object> page = new Page<>(criteria.getPage(), criteria.getSize());
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> param = objectMapper.convertValue(financeAd01, Map.class);
		return new ResponseEntity<>(financeAd02Service.getBills(param, page), HttpStatus.OK);
	}

	@PostMapping("/save")
	@ApiOperation("生成支付计划")
	public ResponseEntity<Object> save(@RequestBody Map resources) throws Exception {
		financeAd02Service.save(new MyMap(resources));
		return new ResponseEntity<>(HttpStatus.CREATED);
	}
}


